package main

import "fmt"

func main() {
	//test1()
	test2()
}

func test1() {
	var c *int //声明一个空指针
	fmt.Println(c)

	var a int = 299
	var b *int = &a                       //指针
	fmt.Printf("a:%v,a的addr:%p\n", a, &a) //a:299,a的addr:0xc000196008
	fmt.Println(b)                        //0xc000196008
	fmt.Println(*b)                       //通过指针获取变量 299

	//通过 *b 将 变量a 更改掉
	*b = 5
	fmt.Println(a)  //5
	fmt.Println(*b) //5
}

func change(val *int) {
	*val = 100
}

func test2() {
	a := 1000000
	fmt.Printf("a:%v\n", a)

	b := &a
	fmt.Printf("b:%v\n", *b)

	change(b)
	fmt.Printf("a:%v\n", a)
}
